using MicroCloud.CodeGenerator.Views.LoadFromEntities;

namespace MicroCloud.CodeGenerator.Views
{
    [Singleton]
    public class MainViewModel : Screen
    {
        private readonly INotificationManager _notificationManager;

        /// <summary>
        /// 初始化一个<see cref="MainViewModel"/>类型的新实例
        /// </summary>
        public MainViewModel()
        {
            DisplayName = "MicroCloud";
            _notificationManager = new NotificationManager(NotificationPosition.BottomRight);
        }

        public MainMenuViewModel MainMenu { get; set; } = IoC.Get<MainMenuViewModel>();

        public StatusBarViewModel StatusBar { get; set; } = IoC.Get<StatusBarViewModel>();

        public ProjectListViewModel ProjectList { get; set; } = IoC.Get<ProjectListViewModel>();

        public MenuViewModel Menu { get; set; } = IoC.Get<MenuViewModel>();

        public ModuleListViewModel ModuleList { get; set; } = IoC.Get<ModuleListViewModel>();

        public EntityListViewModel EntityList { get; set; } = IoC.Get<EntityListViewModel>();

        public ForeignListViewModel ForeignList { get; set; } = IoC.Get<ForeignListViewModel>();

        public PropertyListViewModel PropertyList { get; set; } = IoC.Get<PropertyListViewModel>();

        public TemplateListViewModel TemplateList { get; set; } = IoC.Get<TemplateListViewModel>();

        public ProjectTemplateListViewModel ProjectTemplateList { get; set; } = IoC.Get<ProjectTemplateListViewModel>();

        public AboutViewModel About { get; set; } = IoC.Get<AboutViewModel>();

        public LoadFromEntitiesViewModel LoadFromEntities { get; set; } = IoC.Get<LoadFromEntitiesViewModel>();

        public async Task Notify(string message, NotificationType type = NotificationType.Information, string title = "消息提示")
        {
            NotificationContent content = new NotificationContent()
            {
                Title = title,
                Message = message,
                Type = type
            };
            await _notificationManager.ShowAsync(content, "MainNotifyArea");
        }

        public void MainSave()
        {
            if (ModuleList.IsShow)
            {
                ModuleList.Save();
            }
            else if (EntityList.IsShow)
            {
                EntityList.Save();
            }
            else if (PropertyList.IsShow)
            {
                PropertyList.Save();
            }
            else if (TemplateList.IsShow)
            {
                TemplateList.Save();
            }
            else if (ForeignList.IsShow)
            {
                ForeignList.Save();
            }
        }

        public void LoadRelate()
        {
            ViewModelLocator.Instance.Refresh();
        }
    }
}
